<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="" prop="setmId">
        <el-select v-model="queryParams.setmId" placeholder="请选择体检套餐" clearable>
          <el-option v-for="item in setmOptions" :key="item.setmId" :label="item.name" :value="item.setmId" />
        </el-select>
      </el-form-item>
      <!-- <el-form-item label="" prop="doctor">
        <el-input v-model="queryParams.doctor" placeholder="请输入审核医生" clearable @keyup.enter.native="handleQuery" />
      </el-form-item> -->
      <el-form-item label="" prop="tjUser">
        <el-input v-model="queryParams.tjUser" placeholder="请输入患者姓名" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="" prop="userSex">
        <el-select v-model="queryParams.userSex" placeholder="请选择患者性别" clearable>
          <el-option v-for="dict in dict.type.sys_user_sex" :key="dict.value" :label="dict.label" :value="dict.value" />
        </el-select>
      </el-form-item>
      <!-- <el-form-item label="" prop="healthAssess">
        <el-select v-model="queryParams.healthAssess" placeholder="请选择健康评估" clearable>
          <el-option v-for="dict in dict.type.health_assessment" :key="dict.value" :label="dict.label"
            :value="dict.value" />
        </el-select>
      </el-form-item> -->
      <!-- <el-form-item label="" prop="user">
        <el-input v-model="queryParams.user" placeholder="请输入医嘱" clearable @keyup.enter.native="handleQuery" />
      </el-form-item> -->
      <!-- <el-form-item label="" prop="satisficing">
        <el-select v-model="queryParams.satisficing" placeholder="请选择满意度" clearable>
          <el-option
            v-for="dict in dict.type.assess_result"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item> -->
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8" v-hasRole="['sysadmin', 'doctor']">
      <el-col :span="1.5">
        <el-button type="primary" plain icon="el-icon-plus" size="mini" @click="handleAdd"
          v-hasPermi="['jktj:entering:add']">新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button type="success" plain icon="el-icon-edit" size="mini" :disabled="single" @click="handleUpdate"
          v-hasPermi="['jktj:entering:edit']">修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button type="danger" plain icon="el-icon-delete" size="mini" :disabled="multiple" @click="handleDelete"
          v-hasPermi="['jktj:entering:remove']">删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button type="warning" plain icon="el-icon-download" size="mini" @click="handleExport"
          v-hasPermi="['jktj:entering:export']">导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table border v-loading="loading" :data="enteringList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <!-- <el-table-column label="id" align="center" prop="entId" /> -->
      <el-table-column label="体检套餐" align="center" prop="jktjSetmeal.name" />
      <el-table-column label="审核医生" align="center" prop="doctor" />
      <el-table-column label="患者姓名" align="center" prop="tjUser" />
      <el-table-column label="患者性别" align="center" prop="userSex">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.sys_user_sex" :value="scope.row.userSex" />
        </template>
      </el-table-column>
      <!-- <el-table-column label="身份证号" align="center" prop="identityCard" /> -->
      <!-- <el-table-column label="体检类型" align="center" prop="tjType">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.health_examination_type" :value="scope.row.tjType"/>
        </template>
      </el-table-column> -->
      <!-- <el-table-column label="检查路径" align="center" prop="inspect">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.health_examine" :value="scope.row.inspect ? scope.row.inspect.split(',') : []"/>
        </template>
      </el-table-column> -->
      <!-- <el-table-column label="出现症状" align="center" prop="symptom">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.health_symptom" :value="scope.row.symptom ? scope.row.symptom.split(',') : []"/>
        </template>
      </el-table-column> -->
      <el-table-column label="联系电话" align="center" prop="phone" />
      <!-- <el-table-column label="健康评估" align="center" prop="healthAssess">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.health_assessment" :value="scope.row.healthAssess"/>
        </template>
      </el-table-column> -->
      <!-- <el-table-column label="医嘱" align="center" prop="doctorAdvice" /> -->
      <!-- <el-table-column label="其他内容" align="center" prop="remark" /> -->
      <!-- <el-table-column label="满意度" align="center" prop="satisficing">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.assess_result" :value="scope.row.satisficing"/>
        </template>
      </el-table-column> -->
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width" width="200">
        <template slot-scope="scope">
          <el-row v-hasRole="['sysadmin', 'patient']">
            <el-col :span="12">
              <el-button size="small" type="warning" icon="el-icon-document-add" @click="handleUpdate(scope.row)"
                v-hasPermi="['jktj:entering:edit']">登记</el-button>
            </el-col>
            <el-col :span="12">
              <el-button size="small" type="info" icon="el-icon-view" @click="handleExamine(scope.row)"
                v-hasPermi="['jktj:entering:edit']">报告</el-button>
            </el-col>
          </el-row>
          <!-- <el-button size="small" type="success" icon="el-icon-edit" @click="handleTypeIn(scope.row)"
            v-hasPermi="['jktj:entering:edit']">录入</el-button> -->
          <el-row v-hasRole="['sysadmin', 'doctor']">
            <el-col :span="12">
              <el-button size="small" type="success" icon="el-icon-edit" @click="handleTypeIn(scope.row)"
                v-hasPermi="['jktj:entering:edit']">录入</el-button>
            </el-col>
            <el-col :span="12">


              <el-button size="small" type="danger" icon="el-icon-delete" @click="handleDelete(scope.row)"
                v-hasPermi="['jktj:entering:remove']">删除</el-button>
            </el-col>

          </el-row>

        </template>
      </el-table-column>
    </el-table>

    <pagination v-show="total > 0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize"
      @pagination="getList" />

    <!-- 添加或修改体检结果对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="900px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">

        <el-row>
          <el-col :span="8">
            <el-form-item label="体检套餐" prop="setmId" :disabled="false">
              <el-select v-model="form.setmId" placeholder="请选择体检套餐">
                <el-option v-for="item in setmOptions" :key="item.setmId" :label="item.name" :value="item.setmId"
                  :disabled="true" />
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="患者姓名" prop="tjUser">
              <el-input v-model="form.tjUser" placeholder="请输入患者姓名" />
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="患者性别" prop="userSex">
              <el-select v-model="form.userSex" placeholder="请选择患者性别">
                <el-option v-for="dict in dict.type.sys_user_sex" :key="dict.value" :label="dict.label"
                  :value="dict.value"></el-option>
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="8">
            <el-form-item label="身份证号" prop="identityCard">
              <el-input v-model="form.identityCard" placeholder="请输入身份证号" />
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="联系电话" prop="phone">
              <el-input v-model="form.phone" placeholder="请输入联系电话" />
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="审核医生" prop="doctor">
              <el-input v-model="form.doctor" placeholder="请输入录入医生" :disabled="true" />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <!-- <el-col :span="8">
            
          </el-col> -->
          <el-col :span="14">
            <el-form-item label="健康评估" prop="healthAssess">
              <el-radio-group v-model="form.healthAssess" :disabled="isDisabled">
                <el-radio v-for="dict in dict.type.health_assessment" :key="dict.value" :label="dict.value">{{ dict.label
                }}</el-radio>
              </el-radio-group>
            </el-form-item>
          </el-col>
          <el-col :span="10">

          </el-col>
        </el-row>

        <el-row>
          <el-col :span="12">
            <el-form-item label="医生建议" prop="doctorAdvice">
              <el-input type="textarea" v-model="form.doctorAdvice" placeholder="请输入医嘱" :disabled="isDisabled" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="其他内容" prop="remark">
              <el-input type="textarea" v-model="form.remark" placeholder="请输入其他内容" />
            </el-form-item>
          </el-col>
        </el-row>
        <el-form-item label="体检类型" prop="tjType">
          <el-radio-group v-model="form.tjType">
            <el-radio v-for="dict in dict.type.health_examination_type" :key="dict.value" :label="dict.value">{{
              dict.label }}</el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item label="检查路径" prop="inspect">
          <el-checkbox-group v-model="form.inspect">
            <el-checkbox v-for="dict in dict.type.health_examine" :key="dict.value" :label="dict.value">
              {{ dict.label }}
            </el-checkbox>
          </el-checkbox-group>
        </el-form-item>
        <el-form-item label="出现症状" prop="symptom">
          <el-checkbox-group v-model="form.symptom" :disabled="isDisabled">
            <el-checkbox v-for="dict in dict.type.health_symptom" :key="dict.value" :label="dict.value">
              {{ dict.label }}
            </el-checkbox>
          </el-checkbox-group>
        </el-form-item>

        <!-- <el-form-item label="满意度" prop="satisficing">
          <el-select v-model="form.satisficing" placeholder="请选择满意度">
            <el-option v-for="dict in dict.type.assess_result" :key="dict.value" :label="dict.label"
              :value="dict.value"></el-option>
          </el-select>
        </el-form-item> -->
        <!-- <el-divider content-position="center">体检信息信息</el-divider> -->
        <!-- <el-row :gutter="10" class="mb8">
          <el-col :span="1.5">
            <el-button type="warning" icon="el-icon-plus" size="mini" @click="handleAddJktjCheckInfo">信息登记</el-button>
          </el-col>
          <el-col :span="1.5">
            <el-button type="danger" icon="el-icon-delete" size="mini" @click="handleDeleteJktjCheckInfo">删除</el-button>
          </el-col>
        </el-row> -->
        <!-- <el-table :data="jktjCheckInfoList" :row-class-name="rowJktjCheckInfoIndex"
          @selection-change="handleJktjCheckInfoSelectionChange" ref="jktjCheckInfo">
          <el-table-column type="selection" width="50" align="center" />
          <el-table-column label="序号" align="center" prop="index" width="50" />
          <el-table-column label="项目信息" prop="checkInfo" width="150">
            <template slot-scope="scope">
              <el-input v-model="scope.row.checkInfo" placeholder="请输入项目信息" />
            </template>
          </el-table-column>
          <el-table-column label="检查结果" prop="checkResult" width="150">
            <template slot-scope="scope">
              <el-input v-model="scope.row.checkResult" placeholder="请输入检查结果" />
            </template>
          </el-table-column>
          <el-table-column label="基本单位" prop="unit" width="150">
            <template slot-scope="scope">
              <el-input v-model="scope.row.unit" placeholder="请输入基本单位" />
            </template>
          </el-table-column>
          <el-table-column label="体检医生" prop="tjDoctor" width="150">
            <template slot-scope="scope">
              <el-input v-model="scope.row.tjDoctor" placeholder="请输入体检医生" />
            </template>
          </el-table-column>
          <el-table-column label="检查科室" prop="setmId" width="150">
            <template slot-scope="scope">
              <el-select v-model="scope.row.setmId" placeholder="请选择检查科室">
                <el-option v-for="dict in dict.type.sys_audit" :key="dict.value" :label="dict.label"
                  :value="dict.value"></el-option>
              </el-select>
            </template>
          </el-table-column>
        </el-table> -->
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>

    <!-- 查看体检报告 -->
    <div>
      <el-dialog :title="title" :visible.sync="open1" width="900px" append-to-body>

        <div id="container" width="900px">
          <div class="addForm">
            <!-- <el-divider content-position="center">体检信息信息</el-divider> -->
            <el-form ref="form" :model="form" :rules="rules" label-width="80px">
              <el-divider content-position="center">
                <h1>体检报告</h1>
              </el-divider>
              <el-row>
                <el-col :span="8">
                  <el-form-item label="体检套餐" prop="setmId">
                    <el-select v-model="form.setmId" placeholder="请选择体检套餐">
                      <el-option v-for="item in setmOptions" :key="item.setmId" :label="item.name" :value="item.setmId"
                        :disabled="true" />
                    </el-select>
                  </el-form-item>
                </el-col>
                <el-col :span="8">
                  <el-form-item label="患者姓名" prop="tjUser">
                    <el-input v-model="form.tjUser" placeholder="请输入患者姓名" :disabled="true" />
                  </el-form-item>
                </el-col>
                <el-col :span="8">
                  <el-form-item label="患者性别" prop="userSex">
                    <el-select v-model="form.userSex" placeholder="请选择患者性别" :disabled="true">
                      <el-option v-for="dict in dict.type.sys_user_sex" :key="dict.value" :label="dict.label"
                        :value="dict.value"></el-option>
                    </el-select>
                  </el-form-item>
                </el-col>
              </el-row>
              <el-row>
                <el-col :span="8">
                  <el-form-item label="身份证号" prop="identityCard">
                    <el-input v-model="form.identityCard" placeholder="请输入身份证号" :disabled="true" />
                  </el-form-item>
                </el-col>
                <el-col :span="8">
                  <el-form-item label="联系电话" prop="phone">
                    <el-input v-model="form.phone" placeholder="请输入联系电话" :disabled="true" />
                  </el-form-item>
                </el-col>
                <el-col :span="8">
                  <el-form-item label="审核医生" prop="doctor">
                    <el-input v-model="form.doctor" placeholder="请输入录入医生" :disabled="true" />
                  </el-form-item>
                </el-col>
              </el-row>
              <el-row>
                <el-col :span="14">
                  <el-form-item label="健康评估" prop="healthAssess">
                    <el-radio-group v-model="form.healthAssess" :disabled="isDisabled">
                      <el-radio v-for="dict in dict.type.health_assessment" :key="dict.value" :label="dict.value">{{
                        dict.label
                      }}</el-radio>
                    </el-radio-group>
                  </el-form-item>
                </el-col>
                <el-col :span="10">

                </el-col>
              </el-row>

              <el-row>
                <el-col :span="12">
                  <el-form-item label="医生建议" prop="doctorAdvice">
                    <el-input type="textarea" v-model="form.doctorAdvice" placeholder="请输入医嘱" :disabled="isDisabled" />
                  </el-form-item>
                </el-col>
                <el-col :span="12">
                  <el-form-item label="其他内容" prop="remark">
                    <el-input type="textarea" v-model="form.remark" placeholder="请输入其他内容" :disabled="true" />
                  </el-form-item>
                </el-col>
              </el-row>
              <el-form-item label="体检类型" prop="tjType">
                <el-radio-group v-model="form.tjType" :disabled="true">
                  <el-radio v-for="dict in dict.type.health_examination_type" :key="dict.value" :label="dict.value">{{
                    dict.label }}</el-radio>
                </el-radio-group>
              </el-form-item>
              <el-form-item label="检查路径" prop="inspect">
                <el-checkbox-group v-model="form.inspect" :disabled="true">
                  <el-checkbox v-for="dict in dict.type.health_examine" :key="dict.value" :label="dict.value">
                    {{ dict.label }}
                  </el-checkbox>
                </el-checkbox-group>
              </el-form-item>
              <el-form-item label="出现症状" prop="symptom">
                <el-checkbox-group v-model="form.symptom" :disabled="true">
                  <el-checkbox v-for="dict in dict.type.health_symptom" :key="dict.value" :label="dict.value">
                    {{ dict.label }}
                  </el-checkbox>
                </el-checkbox-group>
              </el-form-item>

              <el-form-item label="满意度" prop="satisficing">
                <el-select v-model="form.satisficing" placeholder="请选择满意度">
                  <el-option v-for="dict in dict.type.assess_result" :key="dict.value" :label="dict.label"
                    :value="dict.value"></el-option>
                </el-select>
              </el-form-item>
              <el-divider content-position="center">
                <h3>体检信息</h3>
              </el-divider>
              <!-- <el-row :gutter="10" class="mb8">
          <el-col :span="1.5">
            <el-button type="warning" icon="el-icon-plus" size="mini" @click="handleAddJktjCheckInfo">信息登记</el-button>
          </el-col>
          <el-col :span="1.5">
            <el-button type="danger" icon="el-icon-delete" size="mini" @click="handleDeleteJktjCheckInfo">删除</el-button>
          </el-col>
        </el-row> -->
              <el-table :data="jktjCheckInfoList" :row-class-name="rowJktjCheckInfoIndex"
                @selection-change="handleJktjCheckInfoSelectionChange" ref="jktjCheckInfo">
                <!-- <el-table-column type="selection" width="50" align="center" /> -->
                <el-table-column label="序号" align="center" prop="index" width="50" />
                <el-table-column label="项目信息" prop="checkInfo" width="150">
                  <template slot-scope="scope">
                    <el-input v-model="scope.row.checkInfo" placeholder="请输入项目信息" :disabled="true" />
                  </template>
                </el-table-column>
                <el-table-column label="检查结果" prop="checkResult" width="150">
                  <template slot-scope="scope">
                    <el-input v-model="scope.row.checkResult" placeholder="请输入检查结果" :disabled="true" />
                  </template>
                </el-table-column>
                <el-table-column label="基本单位" prop="unit" width="150">
                  <template slot-scope="scope">
                    <el-input v-model="scope.row.unit" placeholder="请输入基本单位" :disabled="true" />
                  </template>
                </el-table-column>
                <el-table-column label="体检医生" prop="tjDoctor" width="150">
                  <template slot-scope="scope">
                    <el-input v-model="scope.row.tjDoctor" placeholder="请输入体检医生" :disabled="true" />
                  </template>
                </el-table-column>
                <el-table-column label="检查科室" prop="setmId" width="150">
                  <template slot-scope="scope">
                    <el-select v-model="scope.row.setmId" placeholder="请选择检查科室" :disabled="true">
                      <el-option v-for="dict in dict.type.sys_audit" :key="dict.value" :label="dict.label"
                        :value="dict.value"></el-option>
                    </el-select>
                  </template>
                </el-table-column>
              </el-table>
            </el-form>
          </div>
        </div>



        <div slot="footer" class="dialog-footer">
          <el-button type="warning" icon="el-icon-download" @click="generate">下载体检报告</el-button>
          <!-- <el-button @click="cancel">取 消</el-button> -->
        </div>

      </el-dialog>
    </div>

  </div>
</template>

<script>
import { listEntering, getEntering, delEntering, addEntering, updateEntering } from "@/api/jktj/entering";
import { listSetmeal } from "@/api/jktj/setmeal";
import { listCheckgroup } from "@/api/jktj/checkgroup";
import html2canvas from 'html2canvas';

export default {
  name: "Entering",
  dicts: ['health_examination_type', 'health_symptom', 'sys_common_status', 'health_assessment', 'assess_result', 'sys_user_sex', 'health_examine', 'sys_audit'],
  data () {
    return {
      // 遮罩层
      loading: true,
      isDisabled: false,
      // 选中数组
      ids: [],
      // 子表选中数据
      checkedJktjCheckInfo: [],
      setmOptions: [],
      //当前用户
      crruentUser: this.$store.state.user.name,
      //当前角色
      crruentRole: this.$store.state.user.roles[0],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 体检结果表格数据
      enteringList: [],
      // 体检信息表格数据
      jktjCheckInfoList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      open1: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        setmId: null,
        doctor: null,
        tjUser: null,
        userSex: null,
        healthAssess: null,
        doctorAdvice: null,
        user: null
      },
      // 表单参数
      form: {},
      queryCheckGroup: {
        setmId: null
      },
      // 表单校验
      rules: {
      }
    };
  },
  created () {
    this.getList();
    this.getAllSetmealList();
    console.log(this.$store.state.user)
  },
  methods: {
    //生成体检报告
    generateImage () {
      const element = document.getElementById('container'); // 替换为目标元素的id或class  
      html2canvas(element).then((canvas) => {
        const image = canvas.toDataURL('image/png');
        const link = document.createElement('a');
        link.href = image;
        link.download = 'checkReport.png';
        link.click();
      });
    },
    //
    getAllSetmealList () {
      listSetmeal().then(response => {
        this.setmOptions = response.rows
      })
    },
    /** 查询体检结果列表 */
    getList () {
      // if(this.crruentRole=='sysadmin'||this.crruentRole=='doctor'){

      // }
      if (this.crruentRole == 'patient') {
        this.queryParams.user = this.crruentUser;
      }
      this.loading = true;
      listEntering(this.queryParams).then(response => {
        this.enteringList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel () {
      this.open = false;
      this.reset();
    },
    generate () {
      this.generateImage();
      console.log(111)
    },
    // 表单重置
    reset () {
      this.form = {
        entId: null,
        setmId: null,
        doctor: null,
        tjUser: null,
        userSex: null,
        identityCard: null,
        tjType: null,
        inspect: [],
        symptom: [],
        phone: null,
        healthAssess: null,
        doctorAdvice: null,
        remark: null,
        satisficing: null
      };
      this.jktjCheckInfoList = [];
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery () {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery () {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange (selection) {
      this.ids = selection.map(item => item.entId)
      this.single = selection.length !== 1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd () {
      this.reset();
      this.open = true;
      this.title = "添加体检结果";
    },
    /** 修改按钮操作 */
    handleUpdate (row) {
      this.reset();
      const entId = row.entId || this.ids
      getEntering(entId).then(response => {
        this.form = response.data;
        this.form.inspect = this.form.inspect.split(",");
        this.form.symptom = this.form.symptom.split(",");
        this.jktjCheckInfoList = response.data.jktjCheckInfoList;
        this.open = true;
        this.title = "体检登记";
      });
    },
    handleTypeIn (row) {
      this.reset();
      const entId = row.entId || this.ids
      // console.log(entId)
      getEntering(entId).then(response => {
        // console.log(response.data)
        this.form = response.data;
        this.$router.push({
          path: '/jktj/addResult',
          query: {
            id: row.entId,
            // form: JSON.stringify(this.form)
          }

        })
        // console.log(this.form)
      })
      // console.log(this.form)
    },
    handleExamine (row) {
      this.reset();
      const entId = row.entId || this.ids
      getEntering(entId).then(response => {
        this.form = response.data;
        this.form.inspect = this.form.inspect.split(",");
        this.form.symptom = this.form.symptom.split(",");
        this.jktjCheckInfoList = response.data.jktjCheckInfoList;
        this.open1 = true;
        this.title = "";
      });
    },
    /** 提交按钮 */
    submitForm () {
      this.$refs["form"].validate(valid => {
        if (valid) {
          this.form.inspect = this.form.inspect.join(",");
          this.form.symptom = this.form.symptom.join(",");
          this.form.jktjCheckInfoList = this.jktjCheckInfoList;
          // this.queryCheckGroup.setmId = this.form.setmId;
          // listCheckgroup(this.queryCheckGroup).then(response => {
          //   for (var i = 0; i < response.rows.length; i++) {
          //     let obj = {};
          //     obj.checkInfo = response.rows[i].jktjCheck.checkName;
          //     obj.checkResult = ""
          //     obj.unit = response.rows[i].checkUnit;
          //     obj.tjDoctor = "";
          //     obj.setmId = response.rows[i].setmId;
          //     obj.img = "";
          //     this.jktjCheckInfoList.push(obj);
          //   }
          //   this.form.jktjCheckInfoList = this.jktjCheckInfoList;
          // })
          // console.log(this.form)
          if (this.form.entId != null) {
            updateEntering(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            console.log(this.form)
            addEntering(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete (row) {
      const entIds = row.entId || this.ids;
      this.$modal.confirm('是否确认删除体检结果编号为"' + entIds + '"的数据项？').then(function () {
        return delEntering(entIds);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => { });
    },
    /** 体检信息序号 */
    rowJktjCheckInfoIndex ({ row, rowIndex }) {
      row.index = rowIndex + 1;
    },
    /** 体检信息添加按钮操作 */
    handleAddJktjCheckInfo () {
      let obj = {};
      obj.checkInfo = "";
      obj.checkResult = ""
      obj.unit = "";
      obj.tjDoctor = "";
      obj.setmId = "";
      obj.img = "";
      this.jktjCheckInfoList.push(obj);
    },
    /** 体检信息删除按钮操作 */
    handleDeleteJktjCheckInfo () {
      if (this.checkedJktjCheckInfo.length == 0) {
        this.$modal.msgError("请先选择要删除的体检信息数据");
      } else {
        const jktjCheckInfoList = this.jktjCheckInfoList;
        const checkedJktjCheckInfo = this.checkedJktjCheckInfo;
        this.jktjCheckInfoList = jktjCheckInfoList.filter(function (item) {
          return checkedJktjCheckInfo.indexOf(item.index) == -1
        });
      }
    },
    /** 复选框选中数据 */
    handleJktjCheckInfoSelectionChange (selection) {
      this.checkedJktjCheckInfo = selection.map(item => item.index)
    },
    /** 导出按钮操作 */
    handleExport () {
      this.download('jktj/entering/export', {
        ...this.queryParams
      }, `entering_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
<style>
.addForm {
  margin: 1%;
  border: 1px solid #353434;
}
</style>
